from PyQt5.QtWidgets import QMainWindow, QGridLayout, QLabel, QWidget
from random import randint
import pyperclip

from rublev_get_icons import get_icons


class ClickableLabel(QLabel):
    def __init__(self, *args):
        super().__init__(*args)

    def mousePressEvent(self, QMouseEvent):
        rgb = tuple(map(int, self.styleSheet().split('(')[1].split(')')[0].split(',')))
        hex_color = f'#{rgb[0]:02x}{rgb[1]:02x}{rgb[2]:02x}'
        print(hex_color)
        pyperclip.copy(hex_color)


class Palette(QMainWindow):
    def __init__(self, parent=None):
        super(Palette, self).__init__(parent)
        self.initUI()

    def initUI(self):
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        self.layout = QGridLayout()
        self.setWindowTitle('Pick a color')
        self.layout.setSpacing(0)

        for row in range(5):
            for column in range(5):
                label = ClickableLabel()
                label.setStyleSheet(f'background-color: rgb({randint(0, 255)}, {randint(0, 255)}, {randint(0, 255)});')
                self.layout.addWidget(label, row, column)

        central_widget.setLayout(self.layout)
        print(get_icons(), sep='\n')
